//
//  FeatureTableViewCell.m
//  iBook
//
//  Created by wangjing on 14/12/16.
//  Copyright (c) 2014年 wikiflyer. All rights reserved.
//

#import "FeatureTableViewCell.h"



@implementation FeatureTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+(instancetype)CellWithTableView:(UITableView *)tableView{
//    static NSString *ID = @"cell";
    FeatureTableViewCell *cell = nil;
//    FeatureTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
//    if (!cell) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"FeatureTableViewCell" owner:nil options:nil]firstObject];
//    }
    return cell;
}
-(void)initData:(NSIndexPath *)indexPath{
    
    //显示全部Label添加点击事件
    UITapGestureRecognizer *showTapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickShowAllWithTap:)];
    self.lable_all.userInteractionEnabled = YES;
    [self.lable_all addGestureRecognizer:showTapGesture];
    
    //ScrollView
    CGFloat imgW = 50;
    CGFloat imgH = self.scrollView.frame.size.height;
    CGFloat imgX = 0;
    CGFloat imgY = 0;
    CGFloat imgPad = 5;
    for (int i = 0; i< 10; i++) {
        int cellIndex = (indexPath.row+1) * 1000+i;
        imgX = i*(imgW+imgPad);
        //添加ScrollCell
        FeatureScrollCell *scrollCell = [[FeatureScrollCell alloc]initWithFrame:CGRectMake(imgX, imgY, imgW, imgH)];
        scrollCell.imageView.image = [UIImage imageNamed:@"book_temp.jpg"];
        scrollCell.name.text = [NSString stringWithFormat:@"位置 %d",cellIndex];
        scrollCell.tag = cellIndex;
        [self.scrollView addSubview:scrollCell];
        //为ScrollCell添加点击事件
        UITapGestureRecognizer *celltapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickScrollCellWithTap:)];
        scrollCell.userInteractionEnabled = YES;
        [scrollCell addGestureRecognizer:celltapGesture];
    }
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.contentSize = CGSizeMake(10*(imgW+imgPad), imgH);
}


/**
 *  点击ScrollCell的方法
 */
- (void)clickScrollCellWithTap:(UITapGestureRecognizer *)tapGesture{
    if(self.cellDelegate){
        [_cellDelegate onClickedImageWithTag:tapGesture.view.tag];
    }
}
-(void)clickShowAllWithTap:(UITapGestureRecognizer *)tapGesture{
    if (self.showDelegate) {
        [_showDelegate showBtnClick:tapGesture.view.tag];
    }
}



@end
